class CreateReqImports < ActiveRecord::Migration
  def self.up
    create_table :req_imports do |t|
      t.integer :user_id
      t.integer :project_id
      t.integer :doc_id
      t.string :ref
      t.string :for_refs
      t.text :req
      t.text :comments     
      t.timestamps
    end
    
    add_column :req_rels, :id, :primary_key
    add_column :req_rels, :project_id, :integer
    ReqRel.find(:all).each { |r|
      req = Req.find(:first, :conditions=>"id=#{r.req_from_id}")
      r.project_id = req.project_id if req
      r.save!
      }
  end

  def self.down
    drop_table :req_imports
    remove_column :req_rels, :project_id
    remove_column :req_rels, :id
  end
end
